<template>
  <h6 v-show="isLoading">isLoading</h6>
  <h6 v-show="error">{{ error }}</h6>
  <ul v-show="data">
    <li>{{ data }}</li>
  </ul>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue";
// import { createLogger } from "vuex";
// 导入
import axios from "axios";
export default defineComponent({
  name: "App",
  // 组合式API入口

  setup() {
    const isLoading = ref(false);
    const error = ref("");
    const data = ref([]);

    axios
      .get("https://jsonplaceHolder.typicode.com/posts")
      .then((res) => {
        data.value = res.data;
        isLoading.value = false;
      })
      .catch((err) => {
        error.value = err;
      });

    // 返回值
    return { isLoading, error, data };
  },
  components: {},
});
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
